/**
 * 角色详情对话框
 */
var RoleInfoDlg = {
    data: {
        pid: "",
        pName: ""
    }
};

layui.use(['layer', 'form', 'admin', 'ax','rate','util','carousel'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var layer = layui.layer;
    var rate = layui.rate;
    var util = layui.util;
    var carousel = layui.carousel;
    // 让当前iframe弹层高度适应
    admin.iframeAuto();


    //初始详情数据

    var ajax = new $ax(Feng.ctxPath + "/ticket/ticketDetailData/"  + Feng.getUrlParam("orderId"));
    var result = ajax.start();
    //工单进度
    var bName = "";

    result.data.repairSchedule.forEach(function(item,index){
        var content= '<li class="layui-timeline-item" style="padding-bottom: 38px;"><img  src="/assets/common/images/finish.svg" style="position: absolute;top: -2px;width: 28px;height: 28px"> ' +
            '<div class="layui-timeline-content layui-text" style="margin-left: 14px;">' +
            '<div style="float: left;font-size: 16px;color: rgba(14,31,53,0.85);">'+item.status+'</div>' +
            '<div style="float: right;font-size: 12px;color: rgba(0,0,0,0.45);margin-right: 9px;" class="layui-timeline-title">  '+util.toDateString(new Date(item.createTime).getTime(),"yyyy-MM-dd HH:mm:ss")+'</div>' +
            '<br><div style="font-size: 14px;color: rgba(0,0,0,0.45);     line-height: 20px;\n' +
            '    margin-top: 4px;">'+item.createUserName+'['+item.role+']</div>' +
            '<div style="font-size: 12px;color: rgba(0,0,0,0.45);    line-height: 17px;\n' +
            '    margin-top: 10px;word-break: break-all;">'+item.posOperationDesc+'</div> </div> </li>'
        $("#repairSchedule").append(content)

    })
    //报事图片
    var temp = 0,temp2=0;
    var imgAaary = result.data.submitImages==''?[]: result.data.submitImages.split(',')
    imgAaary.forEach(function(img,index){
        $("#submitImages").append('<div class="swiper-slide"><img src="'+img+'" class="repair-img"  />')
        temp = temp+1;
        if(temp>3){
            $("#b1").css('display','block');
        }
    })
    var typeName = $("#typeName").val();
    if(typeName=='已完成'){
        $("#seal").append('<img style="height: 100px;width: 1000px;"  src="/assets/common/images/success.svg"/>')
    }else if(typeName=='无法处理'){
        $("#seal").append('<img style="height: 100px;width: 1000px;"  src="/assets/common/images/mishandle.svg"/>')
    }else if(typeName=='已作废'){
        $("#seal").append('<img style="height: 100px;width: 1000px;"  src="/assets/common/images/cancel.svg"/>')
    }
    $("#submitImages").on("click",".repair-img",function () {
        previewImg($(this).attr("src"))
    })

    //处理图片
    var imgAaary = result.data.endImages==''?[]: result.data.endImages.split(',')
    imgAaary.forEach(function(img,index){
        $("#endImages").append('<div class="swiper-slide"><img src="'+img+'" class="repair-img"  /></div>')
        temp2 = temp2+1;
    })
    if(temp2>3){
        $("#b2").css('display','block');
    }
    $("#endImages").on("click",".repair-img",function () {
        previewImg($(this).attr("src"))
    })

    //详情字段填充
    //$("#orderNo").text(result.data.orderNo)//订单号
    //$("#shopName").text(result.data.shopName)//商户名
    //$("#shopAdr").text(result.data.shopAdr)//商户地址
    $("#contactName").text(result.data.contactName)//报事人
    $("#contactPhone").text(result.data.contactPhone)//报事人电话
    $("#operatorName").text(result.operatorName)//处理人
    $("#createTime").text(util.toDateString(new Date(result.data.createTime).getTime(),'yyyy-MM-dd HH:mm:ss'))//报事时间
    $("#repairType").text(result.data.repairType)//报事类型
    $("#describes").text(result.data.describes)//报事内容
    $("#orderPrice").text(result.data.orderPrice)//报事费用
    if(result.data.type==11){
        $("#photoName").text("维修完成:")
    }else if(result.data.type==12){
        $("#photoName").text("无法处理:")
    }
    admin.iframeAuto();


});


//调整预览大小
function previewImg(src) {
    var img = new Image();
    img.src = src;
    var imgHtml = "<img src='" + src + "' width='100%' height='100%'/>";
    //弹出层
    layer.open({
        type: 1,
        shade: 0.8,
        offset: 'auto',
       // area: [600 + 'px',300+'px'],
        shadeClose:true,
        scrollbar: false,
        title: "图片预览", //不显示标题
        content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
        cancel: function () {
            //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 });
        }
    });
}

//原图预览
function previewImgs(src) {
    var img = new Image();
    img.src = src;
    var height = img.height + 50; //获取图片高度
    var width = img.width; //获取图片宽度
    var imgHtml = "<img src='" + src + "' />";
    //弹出层
    layer.open({
        type: 1,
        shade: 0.8,
        offset: 'auto',
        area: [width + 'px',height+'px'],
        shadeClose:true,//点击外围关闭弹窗
        scrollbar: false,//不现实滚动条
        title: "图片预览", //不显示标题
        content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
        cancel: function () {
            //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 });
        }
    });

}
var swiper = new Swiper('.swiper1', {
    slidesPerView: 3,
    spaceBetween: 12,
    navigation: {
        nextEl: '.n1',
        prevEl: '.p1'
    }
});
var swiper1 = new Swiper('.swiper2', {
    slidesPerView: 3,
    spaceBetween: 12,
    navigation: {
        nextEl: '.n2',
        prevEl: '.p2'
    }
});